// pagetableentry.h 
//	Data structures for managing the translation from 
//	virtual page # -> physical page #, used for managing
//	physical memory on behalf of user programs.
//
//	The data structures in this file are "dual-use" - they
//	serve both as a page table entry, and as an entry in
//	a software-managed inverted page table (IPT).
//	Either way, each entry is of the form:
//	<virtual page #, physical page #>.

#include "copyright.h"
#include "utility.h"

#define PAGE_CODE 	1
#define PAGE_DATA 	2
#define PAGE_MIXED 	3
#define PAGE_STACK	4
#define PAGE_TYPE_UNKNOWN 5

#define PAGE_MEMORY 	 1
#define PAGE_SWAPFILE 	 2
#define PAGE_EXECUTABLE  3
#define PAGE_LOC_UNKNOWN 4

typedef int PageType;
typedef int PageLocation;

// The following class defines an entry in a translation table -- either
// in a page table or a IPT.  Each entry defines a mapping from one 
// virtual page to one physical page.
// In addition, there are some extra bits for access control (valid and 
// read-only) and some bits for usage information (use and dirty).
// also records the current location of the page (exec, swapfile, memory)
// and the last time stamp of when it was used. 

class PageTableEntry {
  public:
	PageTableEntry() {
		virtualPage = -1;
		physicalPage = -1;
		valid = false;
		readOnly = false;
		use = false;
		dirty = false;
		pageType = PAGE_TYPE_UNKNOWN;
		pageLocation = PAGE_LOC_UNKNOWN;
		processId = -1;
		timestamp = -1;
	}
    int virtualPage;  	// The page number in virtual memory.
    int physicalPage;  	// The page number in real memory (relative to the
			//  start of "mainMemory"
    bool valid;         // If this bit is set, the translation is ignored.
			// (In other words, the entry hasn't been initialized.)
    bool readOnly;	// If this bit is set, the user program is not allowed
			// to modify the contents of the page.
    bool use;       // This bit is set by the hardware every time the
								// page is referenced or modified.
    bool dirty;     // This bit is set by the hardware every time the
								// page is modified.
	PageType pageType; 			// The type of the page (code, data, mixed, etc)
	PageLocation pageLocation; 	// current location of the page (main memory,
								// swapfile, executable, etc.)
	int processId;		// spaceId of the process that owns this page.

	int timestamp;		// timestamp of when this page was last used. Used for LRU
						// replacement policy
};
